#include <stdio.h>
#include <memory.h>

int main( )
{
    bool su[ 10000 ];
    int i, j, n;
    memset( su, 1, sizeof( su ) );
    su[ 0 ] = su[ 1 ] = false;
    for ( i = 2; i < 10000; i++ )
        if ( su[ i ] )
            for ( j = i * 2; j < 10000; j += i )
                su[ j ] = false;
    while ( scanf("%d", &n) != EOF )
    {
        if ( n == 0 ) break;
        int t = 0;
        for ( i = 2; i < n / 2; i++ )
            if ( su[ i ] && su[ n - i ] )
                t++;
        printf("%d\n", t);
    }
    return 0;
}
